using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using TMPro;


namespace Manaddiction.UI
{
    public class CollectionCard : MonoBehaviour
    {
        public CardUI card_ui;
        public Image quantity_bar;
        public TextMeshProUGUI quantity;
        
        public UnityAction<CardUI> onClick;
        public UnityAction<CardUI> onClickRight;

        private void Start()
        {
            // 确保事件绑定
            if (card_ui != null)
            {
                card_ui.onClick += (card) => onClick?.Invoke(card);
                card_ui.onClickRight += (card) => onClickRight?.Invoke(card);
            }
        }
        
        public void SetCard(CardData card, int quantity)
        {
            card_ui.SetCard(card);
            if (this.quantity_bar != null)
                this.quantity_bar.enabled = quantity > 0;
            if (this.quantity != null)
                this.quantity.text = quantity.ToString();
            if (this.quantity != null)
                this.quantity.enabled = quantity > 0;
        }
        
        public CardData GetCard()
        {
            return card_ui.GetCard();
        }
    }
}
